<template>


  <div class="login-box">
    <div class="login-form">
      <el-form
        :model="form"
        status-icon
        :rules="rules"
        ref="form"
        label-width="100px"
      >
        <el-form-item label="账号" prop="username">
          <el-input
            v-model="form.username"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            type="password"
            v-model="form.password"
          
          ></el-input>
        </el-form-item>
    
        <el-form-item>
          <el-button type="primary" @click="submitForm()"
            >提交</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<style>
.login-box {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}
.login-form{
    margin-top:210px;
    width: 350px;
}
.el-form-item__content{
display: flex;
justify-content: center;
}
</style>


<script>
import Cookie from 'js-cookie'
import { getMenu } from '../api/index.js';
export default {
  data() {
    return {
      form: {
        username:'',
        password:''
      },
      rules: {
        username:[
            {required: true, message: '请输入用户名', trigger: 'blur'}
        ],
          password:[
            {required: true, message: '请输入密码', trigger: 'blur'}
        ],
      },
    };
  },
  methods: {
    submitForm() {
        this.$refs.form.validate((val)=>{
            if(val){
                getMenu(this.form).then(({data})=>{
                    if(data.code===20000){
                        Cookie.set('token',data.data.token)
                        // 跳转
                        this.$router.push('/home')
                    }else{
                        this.$message.error(data.data.message)
                    }

                })
            }
        })
    },
  },
};
</script>